package pers.jing.android.helper

import app.cash.sqldelight.db.SqlDriver
import app.cash.sqldelight.driver.jdbc.sqlite.JdbcSqliteDriver
import org.koin.dsl.module
import pers.jing.android.helper.page.SettingsViewModel
import pers.jing.android.helper.db.Database
import java.io.File
import org.koin.core.module.dsl.viewModel
import pers.jing.android.helper.page.DeviceListViewModel
import pers.jing.android.helper.page.DeviceViewModel
import pers.jing.android.helper.page.MainViewModel
import pers.jing.android.helper.widget.InstallApkViewModel
import pers.jing.android.helper.work.WorkManager

val appModule = module {
    single<SqlDriver> {
        val appDataDir = getAppDataDir()
        val dbFile = File(appDataDir, "app.db")
        JdbcSqliteDriver("jdbc:sqlite:${dbFile.absolutePath}")
    }
    single<Database> {
        Database(get())
    }
    viewModel {
        MainViewModel(database = get(), deviceManager = get())
    }
    viewModel {
        SettingsViewModel(database = get<Database>())
    }
    viewModel {
        DeviceListViewModel(database = get<Database>(), deviceManager = get())
    }
    single {
        WorkManager()
    }

    single {
        DeviceManager(get())
    }

    viewModel {
        DeviceViewModel(database = get(), deviceManager = get(), workManager = get())
    }

    viewModel {
        InstallApkViewModel(deviceManager = get())
    }
}